package com.castday2.castday2.test;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.castday2.castday2.bean.User;
import com.castday2.castday2.mapper.UserMapper;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author : 徐闯 mpcast
 * @Date : 2021-05-24 12:05:23
 * @Description : 测试删除操作
 **/
@RunWith(SpringRunner.class)
@SpringBootTest
public class C_TestDelete {
    @Autowired
    private UserMapper userMapper;
    @Test
    // 根据id删除 一条数据
    public void test1(){
       int n = userMapper.deleteById(1001);
        System.out.println("受影响的数据条数 ==> "+n);
    }
    // 根据id删除多条数据
    @Test
    public void test2(){
        List<Integer> list = new ArrayList();
        list.add(1001);
        list.add(1002);
        list.add(1003);
        int n = userMapper.deleteBatchIds(list);
        System.out.println("受影响的数据条数 ==> "+n);
    }
    // 根据其他列进行删除
    @Test
    public void test3(){
        Map map = new HashMap();
        map.put("name","xc");
        map.put("age",20);
        int n = userMapper.deleteByMap(map);
        System.out.println("受影响的数据条数 ==> "+n);
    }
    // 根据条件构造器进行删除
    @Test
    public void test4(){
        int n = userMapper.delete(Wrappers.<User>query()
            .likeRight("name"," ")
        );
        System.out.println("受影响的数据条数 ==> "+n);
    }
}
